//
//  YWSearchResultController.m
//  YunWu
//
//  Created by 古俊杰 on 2017/5/31.
//  Copyright © 2017年 曲虹亮. All rights reserved.
//

#import "YWSearchResultController.h"
#import "JGSecondViewController.h"

#define RGB(r, g, b)      [UIColor colorWithRed:r/255.0 green:g/255.0 blue:b/255.0 alpha:1]

@interface YWSearchResultController () <UITableViewDelegate,UITableViewDataSource>

@end

@implementation YWSearchResultController


- (void)viewDidLoad {
    [super viewDidLoad];
    
    self.edgesForExtendedLayout = UIRectEdgeNone;
    self.extendedLayoutIncludesOpaqueBars = NO;
    self.modalPresentationCapturesStatusBarAppearance = NO;
    self.navigationController.navigationBar.translucent = NO;
    
    self.view.backgroundColor = RGB(247, 247, 249);
    
    self.tableView.tableFooterView = [UIView new];
    
}

- (void)didReceiveMemoryWarning {
    [super didReceiveMemoryWarning];
    // Dispose of any resources that can be recreated.
}

#pragma mark - Table view data source

- (CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath
{
    return 50;
}

- (NSInteger)numberOfSectionsInTableView:(UITableView *)tableView
{
    return 3;
    
}

- ( NSString *)tableView:( UITableView *)tableView titleForHeaderInSection:( NSInteger )section
{
    return @[@"标题1",@"标题2",@"标题3"][section];
}

- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section
{
    return 3;
}

//section后面会有留白，所以要解决掉
- (CGFloat)tableView:(UITableView *)tableView heightForHeaderInSection:(NSInteger)section
{
    return 35.0f;
}

-(CGFloat)tableView:(UITableView *)tableView heightForFooterInSection:(NSInteger)section
{
    return 0.01f;
}

- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
{
    static NSString* identifier = @"searchResult";
    
    UITableViewCell* cell = [tableView dequeueReusableCellWithIdentifier:identifier];
    if (cell == nil)
    {
        cell = [[UITableViewCell alloc] initWithStyle:UITableViewCellStyleDefault
                                 reuseIdentifier:identifier];
        cell.selectionStyle = UITableViewCellSelectionStyleDefault;
        
        cell.backgroundColor = [UIColor whiteColor];
        
    }
    
    return cell;
}

-(void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath
{
    [tableView deselectRowAtIndexPath:indexPath animated:YES];
    
    if (indexPath.row == 0) {
        
        if (self.cancelSearch) {
            self.cancelSearch(YES);
        }
        
        JGSecondViewController *vc = [JGSecondViewController new];
        vc.title = @"返回取消搜索状态";
//        vc.hidesBottomBarWhenPushed = YES;
        [_baseViewController.navigationController pushViewController:vc animated:YES];
        
    } else {
        
        JGSecondViewController *vc = [JGSecondViewController new];
        //        vc.hidesBottomBarWhenPushed = YES;
        vc.title = @"返回保留搜索状态";
        [_baseViewController.navigationController pushViewController:vc animated:YES];
        
    }
}

#pragma mark - 延迟加载关键
- (void)scrollViewWillBeginDragging:(UIScrollView *)scrollView
{
    if (self.cancelSearch) {
        self.cancelSearch(NO);
    }
}








@end
